package com.desiy.utils;

import lombok.Data;

@Data
public class ResponseDTO {

    /** 200:操作成功  -1：操作失败**/

    // http 状态码
    private int code;

    // 返回信息
    private String msg;

    // 返回的数据
    private Object data;

    public ResponseDTO(){}

    public ResponseDTO(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static ResponseDTO error(String message) {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setMsg(message);
        responseDTO.setCode(-1);
        return responseDTO;
    }

    public static ResponseDTO error(int code,String message) {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setMsg(message);
        responseDTO.setCode(code);
        return responseDTO;
    }

    public static ResponseDTO success(Object data) {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setData(data);
        responseDTO.setCode(200);
        responseDTO.setMsg("成功");
        return responseDTO;
    }

    public static ResponseDTO success(String message) {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setData(null);
        responseDTO.setCode(200);
        responseDTO.setMsg(message);
        return responseDTO;
    }

    public static ResponseDTO success() {
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setData(null);
        responseDTO.setCode(200);
        responseDTO.setMsg("Success");
        return responseDTO;
    }
}
